<template>
  <div>
    <div style="text-align: left;margin: 10px">
      <el-button type="primary" @click="insertTheme">添加新主题</el-button>
    </div>
    <el-table
      :data="tableTheme"
      border
      style="width: 100%"
      height="100vh">
      <el-table-column
        fixed
        prop="basicsname"
        label="主题名">
      </el-table-column>
      <el-table-column
        prop="choice"
        header-align="center"
        align="center"
        sortable
        label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.choice == '启用' ? 'success' : 'danger'">
            <span v-text="scope.row.choice == '启用' ? '启用' : '禁用'"></span>
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="meaningtime"
        label="日期" width="160">
      </el-table-column>
      <el-table-column
        prop="author"
        label="作者">
      </el-table-column>
      <el-table-column
        prop="mainTitle"
        label="主标题">
      </el-table-column>
      <el-table-column
        prop="record"
        label="备案号"
        width="160">
      </el-table-column>
      <el-table-column
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button
            type="success"
            size="small"
            circle
            icon="el-icon-check"
            @click.native.prevent="checktheme(scope.$index, tableTheme)"></el-button>
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            size="small"
            @click.native.prevent="openvalue(scope.$index, tableTheme)"></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            size="small"
            @click.native.prevent="deleteRow(scope.$index, tableTheme)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "ThemeSettingView",
  inject: ['reload'],
  data() {
    return{
      tableTheme: []
    }
  },
  created() {
    this.getThemeData()
  },
  methods:{
    reloadtheme(){
      this.reload()
    },
    getThemeData(){
      this.axios.get(this.Global.BASE_URL+'/Theme/getThemes').then((res)=>{
        if("2000" == res.data.msg){
          this.tableTheme = res.data.data
        }
        else this.$CustomMessage_ERROR('主题','主题查询错误！');
      }).catch(erroe=>{
        this.$CustomMessage_ERROR('主题','主题错误！');
      })
    },
    //增修删
    insertTheme(){
      this.$parent.$parent.$parent.showSetting(0,2)
    },
    openvalue(index, rows){
      this.$parent.$parent.$parent.showSetting(this.tableTheme[index].basicsid,2)
    },
    checktheme(index, rows){
      this.axios.post(this.Global.BASE_URL+'/Theme/ALLTheme',{I:this.tableTheme[index].basicsid}).then((res)=>{
        if("2000" == res.data.msg){
          this.$CustomMessage_OK('主题','更换新主题成功！')
          this.reloadtheme()
        }
        else this.$CustomMessage_ERROR('主题','主题无法选择！');
      }).catch(erroe=>{
        this.$CustomMessage_ERROR('主题','主题错误！');
      })
    },
    deleteRow(index, rows) {
      this.$confirm('此操作将永久删除该主题, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.post(this.Global.BASE_URL+'/Theme/DeleteTheme',{I:this.tableTheme[index].basicsid}).then((res)=>{
          if("2000" == res.data.msg){
            rows.splice(index, 1);
            this.$CustomMessage_OK('主题','删除主题完成！')
          }
          else this.$CustomMessage_ERROR('主题','主题无法删除！');
        }).catch(erroe=>{
          this.$CustomMessage_ERROR('主题','主题错误！');
        })
      }).catch(() => {
      });
    }
  }
}
</script>

<style scoped>

</style>
